<?php

defined('IN_IA') or exit('Access Denied');
require_once 'jssdk.php';
require_once IA_ROOT . '/addons/tim_welfare/WxPayPubHelper/WxPayPubHelper.php';
class Tim_welfareModuleSite extends WeModuleSite
{
	public function doMobileIndex()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
	}

	//修改立即捐款的状态
	public function doMobileUpfund()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$fund_id = $_GPC['fund_id'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$fundtrue = array(
			'fund_true' => 1,
			);
		$result = pdo_update('tim_welfare_fund',$fundtrue,array("fund_id" => $fund_id));
		return json_encode($result);
	}
	//第一人分享一起捐保存
	public function doMobileTogether()
	{
		global $_W, $_GPC;
		$mem_id = $this->checkuser();
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		// $mem_id = $_W['mem_id'];
		$pro_id = $_GPC['pro_id'];
		$other_id = $_GPC['other_id'];
		$bgpic = $_GPC['bgpic'];
		$logo = $_GPC['logo'];
		$goal = $_GPC['goal'];
		$kouhao = $_GPC['kouhao'];
		$gift_time = time();
		$gift_data = array(
		    'mem_id' => $mem_id,
		    'pro_id' => $pro_id,
		    'uniacid' => $uniacid,
		    'other_id' => $other_id,
		    'bgpic' => $bgpic,
		    'logo' => $logo,
		    'goal'=> $goal,
		    'kouhao'=> $kouhao,
		    'gift_time'=> $gift_time,
		);
		$gift_id = '';
		if (!empty($gift_data)) {
			// $update = 'ON DUPLICATE KEY UPDATE'.tablename('tim_welfare_gift').' SET mem_id='.$mem_id.',pro_id='.$pro_id.',uniacid='.$uniacid.',other_id='.$other_id.',img='.$img.',logo='.$logo.',target='.$target.',gift_time='.$gift_time;
			// $sql = 'INSERT INTO'.tablename('tim_welfare_gift') .'values('.$mem_id.','.$pro_id.','.$uniacid.','.$other_id.','.$img.','.$logo.','.$target.','.$gift_time.')'.$update;
			// $result = pdo_query($sql,array(":uniacid" => 2));
			$result = pdo_insert('tim_welfare_gift', $gift_data);
			$gift_id = pdo_insertid();
		}
		return json_encode($gift_id);
	}

	//其余人分享一起捐保存

	//一起捐页面展示
    public function doMobileMyyqz()
    {
    	global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$mem_id = $this->checkuser();
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$params = array(":mem_id" => $mem_id);
		//发起一起捐次数
		$gift_num_sql = 'SELECT * FROM ' . tablename('tim_welfare_gift') . ' 
			WHERE other_id = :mem_id GROUP BY mem_id';
		$gift_num_query = pdo_fetchall($gift_num_sql, $params);
		//小伙伴参与
		$gift_hb_sql = 'SELECT * FROM ' . tablename('tim_welfare_gift') . ' 
			WHERE other_id = :mem_id GROUP BY mem_id';
		$gift_hb_query = pdo_fetchall($gift_hb_sql, $params);
		//共募善款
		$mem_sql = 'select mem_id FROM ' . tablename('tim_welfare_gift') . ' WHERE other_id = :mem_id GROUP BY mem_id';
		$gift_sql = 'select gift_id FROM ' . tablename('tim_welfare_gift') . ' WHERE other_id = :mem_id';
		$gift_jk_sql = 'SELECT sum(fund_value) as sum FROM '. tablename('tim_welfare_fund') .' WHERE fund_true = 1 and gift_id in ('.$gift_sql.') and mem_id in ('.$mem_sql.')';
		$gift_jk_query = pdo_fetchall($gift_jk_sql, $params);
		//一起捐项目列表
		
		// $pro_sql = 'select pro_id FROM' . tablename('tim_welfare_gift') . ' WHERE other_id = :mem_id GROUP BY mem_id';
		// $gift_fund_sql = 'select mem_id FROM' . tablename('tim_welfare_gift') . ' WHERE other_id = :mem_id GROUP BY mem_id';
		// $gift_pro_sql = 'SELECT pro_feature,pro_name,pro_id FROM ' .tablename('tim_welfare_project') .'WHERE pro_id in ('.$pro_sql.')';
		// $pro_fund_sql = 'SELECT pro_id FROM ' .tablename('tim_welfare_project') .'WHERE pro_id in ('.$pro_sql.')';
		// $gift_pro_query = pdo_fetchall($gift_pro_sql, $params);

		// $fund_arr = array();
		// foreach ($gift_pro_query as $k) {
		// 	$fund_sql = 'SELECT count(DISTINCT mem_id) as count,sum(fund_value) as sum FROM ' .tablename('tim_welfare_fund') .'WHERE pro_id = '.$k['pro_id'].' and mem_id in ('.$gift_fund_sql.')';
		// 	$fund_query = pdo_fetchall($fund_sql, $params);
		// 	array_push($fund_arr, $fund_query);
		// }
		// $list = array();
		// for ($i=0; $i < count($gift_pro_query); $i++) { 
		// 	$gift_arr = array("pro_id"=> $gift_pro_query[$i]['pro_id'],"pro_name"=>$gift_pro_query[$i]['pro_name'],"pro_feature"=>$gift_pro_query[$i]['pro_feature'],"count"=>$fund_arr[$i][0]['count'],"sum"=>$fund_arr[$i][0]['sum']);
		// 	array_push($list, $gift_arr);
		// }
		$gift_pro_sql = 'SELECT f.gift_id as gift_id,g.mem_id as mem_id,p.pro_name as pro_name,p.pro_feature as pro_feature FROM'. tablename('tim_welfare_gift') .' g 
LEFT JOIN '. tablename('tim_welfare_project') .' p
on g.pro_id = p.pro_id
and g.uniacid = p.uniacid
LEFT JOIN '. tablename('tim_welfare_fund') .' f
on g.mem_id = f.mem_id
and g.pro_id = f.pro_id
WHERE g.other_id = :mem_id GROUP BY gift_id ORDER BY gift_id DESC';
		$gift_pro_query = pdo_fetchall($gift_pro_sql, $params);
		$list = array();
		foreach ($gift_pro_query as $k) {
			$fund_pro_sql = 'SELECT sum(fund_value) as sum,count(mem_id) as count FROM'. tablename('tim_welfare_fund') .'WHERE gift_id = :gift_id ORDER BY gift_id DESC';
			$fund_pro_query = pdo_fetch($fund_pro_sql,array(":gift_id" => $k['gift_id']));
			$gift_arr = array("gfid" => $k['gfid'],"gift_id" => $k['gift_id'],"pro_name" => $k['pro_name'],"pro_feature" => $k['pro_feature'],"sum" => $fund_pro_query['sum'],"count" => $fund_pro_query['count']);
			array_push($list, $gift_arr);
		}

		
		// print_r($list);
		// exit;
        $title = '我的一起捐';
        include $this->template('myyqz');
    }

    //时间差方法
    public function timeunits($time)
    {
    	$year   = floor($time / 60 / 60 / 24 / 365);
	  	$time  -= $year * 60 * 60 * 24 * 365;
	   	$month  = floor($time / 60 / 60 / 24 / 30);
	   	$time  -= $month * 60 * 60 * 24 * 30;
	   	$week   = floor($time / 60 / 60 / 24 / 7);
	   	$time  -= $week * 60 * 60 * 24 * 7;
	   	$day    = floor($time / 60 / 60 / 24);
	   	$time  -= $day * 60 * 60 * 24;
	   	$hour   = floor($time / 60 / 60);
	   	$time  -= $hour * 60 * 60;
	   	$minute = floor($time / 60);
	   	$time  -= $minute * 60;
	   	$second = $time;
	   	$elapse = '';

	   	$unitArr = array('年'  =>'year', '个月'=>'month',  '周'=>'week', '天'=>'day',
	                    '小时'=>'hour', '分钟'=>'minute', '秒'=>'second'
	                    );

	   	foreach ( $unitArr as $cn => $u )
	   	{
	       	if ( $$u > 0 )
	       	{
	           	$elapse = $$u . $cn;
	           	break;
	       	}
	   	}

	   	return $elapse;
    }
    public function doMobileTip()
    {
        $title = '消息中心';
        include $this->template('tip');
    }

	public function doMobileWelfare()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$this->checkuser();
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$adv = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_adv') . ' WHERE uniacid=:uniacid AND position=:position', array(":uniacid" => $uniacid, ":position" => "0"));
		$classes = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$feature = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid AND pro_stick=:pro_stick ORDER BY pro_id DESC LIMIT 2', array(":pro_stick" => 1, ":uniacid" => $uniacid));
		$id = $_GPC['id'];
		if (!empty($id)) {
			$where = 'and class_id=' . $id;
		}
		$pro_lists = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid ' . $where . ' ORDER BY pro_id DESC LIMIT 20 ', array(":uniacid" => $uniacid));
		$slides = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_slide') . ' WHERE uniacid = :uniacid order by xh', array(":uniacid" => $uniacid));
		$total_pro = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$total_fund = 0;
		foreach ($total_pro as $p) {
			$total_fund += pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_fund') . ' WHERE fund_true=:fund_true AND pro_id=:pro_id', array(":fund_true" => true, ":pro_id" => $p['pro_id']));
		}
		$pro_list = array();
		$class_row = array();
		$feature_list = array();
		foreach ($feature as $k) {
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$fea_totals = floatval($money_totals['total']);
			$fea_data = array("pro_id" => $k['pro_id'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($fea_totals), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick']);
			array_push($feature_list, $fea_data);
		}
		foreach ($classes as $k) {
			$class_num = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid AND class_id=:class_id', array(":uniacid" => $uniacid, ":class_id" => $k['class_id']));
			$class_data = array("class_id" => $k['class_id'], "class_name" => $k['class_name'], "class_num" => $class_num);
			array_push($class_row, $class_data);
		}
		foreach ($pro_lists as $k) {
			$class_name = pdo_fetch('SELECT class_name  FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid = :uniacid AND class_id = :class_id', array(":uniacid" => $uniacid, ":class_id" => $k['class_id']));
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$fund_totals = floatval($money_totals['total']);
			$rows = array("pro_id" => $k['pro_id'], "class_name" => $class_name['class_name'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($fund_totals), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_rate" => round(floatval($fund_totals) / $k['pro_goal'], 5) * 100);
			array_push($pro_list, $rows);
		}
		//捐款时间滚动
			$sql = 'SELECT max(f.fund_time) as fund_time,m.mem_name,p.pro_name FROM ' . tablename('tim_welfare_fund') . ' f
			left join ' . tablename('tim_welfare_member') . ' m on f.mem_id=m.mem_id left join ' . tablename('tim_welfare_project') . ' p
			on f.pro_id = p.pro_id
			WHERE p.uniacid = :uniacid and f.fund_true=:fund_true and f.type = :type and m.uniacid = p.uniacid GROUP BY p.pro_id,m.mem_id ORDER BY fund_time DESC LIMIT 0,10';
			$time_totals = pdo_fetchall($sql,array(":uniacid" => $uniacid,":fund_true" => true,":type" => "MONEY"));
			$ftime = array();
			foreach ($time_totals as $k) {
				$fund_time = time() - $k['fund_time'];
				$front_time = $this->timeunits($fund_time);
				$time_arr = array("mem_name" => $k['mem_name'],"fund_time" => $front_time,"pro_name" => $k['pro_name']);
				array_push($ftime, $time_arr);
			}
		// 项目类型分类搜索
			$class_count = array();
			foreach ($classes as $k) {
				$pro_query = pdo_fetchall('SELECT * FROM' . tablename('tim_welfare_project') . ' WHERE class_id = :class_id and uniacid = :uniacid',array(":class_id" => $k['class_id'],":uniacid" => $uniacid));
				$class_arr = array("class_id" => $k['class_id'],"class_name" => $k['class_name'],"count" => count($pro_query));
				array_push($class_count, $class_arr);
			}
		//----分割线----对接微公益队伍数据
			$join = json_decode($this->http_request('https://www.wgywsy.com/wap/index.php?ctl=postulant&act=apiGetTeamList'),true);
			foreach ($join['data'] as $k) {
				$join_id = $k['id'];
				$join_name = $k['name'];
				$join_logo = addslashes($k['logo']);

				$join_update = 'ON DUPLICATE KEY UPDATE join_id=:join_id,join_name=:join_name,join_logo=:join_logo,uniacid=:uniacid';
				$join_sql = 'INSERT INTO '.  tablename('tim_welfare_ranks') . '(join_id,join_name,join_logo,uniacid) values(:join_id,:join_name,:join_logo,:uniacid)' . $join_update;
				$params = array(":join_id" => $join_id,":join_name" => $join_name,":join_logo" => $join_logo,":uniacid" => $uniacid);
				$join_result = pdo_query($join_sql,$params);
			}

		$title = '公益首页';
		include $this->template('index');
	}

	//发起项目队伍搜索
    public function doMobileSearchjoin()
    {
    	global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$name = $_GPC['name'];
		$ranks = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_ranks') . ' WHERE join_name like \'%' .$name. '%\' and uniacid=:uniacid', array(":uniacid" => $uniacid));
		$url = $_W['attachurl'];
		$arr = array("url" => $url, "ranks" => $ranks);
		echo json_encode($arr);
    }

	//搜索项目
	public function doMobileSearchfare()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$content = $_GPC['content'];
		$pro_lists = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_name like \'%' . $content . '%\' and uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pro_list = array();
		foreach ($pro_lists as $k) {
			$class_name = pdo_fetch('SELECT class_name  FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid = :uniacid AND class_id = :class_id', array(":uniacid" => $uniacid, ":class_id" => $k['class_id']));
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$fund_totals = floatval($money_totals['total']);
			$rows = array("pro_id" => $k['pro_id'], "class_name" => $class_name['class_name'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($fund_totals), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_rate" => round(floatval($fund_totals) / $k['pro_goal'], 5) * 100);
			array_push($pro_list, $rows);
		}
		$url = $_W['attachurl'];
		$arr = array("url" => $url, "pro_list" => $pro_list,"count" => count($pro_list));
		echo json_encode($arr);
	}

	//搜索项目类别
	public function doMobileSearchclass()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$class_id = $_GPC['class_id'];
		$pro_list = array();
		if (!empty($class_id)) {
			$pro_list = pdo_fetchall('SELECT * FROM' . tablename('tim_welfare_project') . ' WHERE class_id = :class_id and uniacid = :uniacid',array(":class_id" => $class_id,":uniacid" => $uniacid));
		}else{
			$pro_list = pdo_fetchall('SELECT * FROM' . tablename('tim_welfare_project') . ' WHERE uniacid = :uniacid',array(":uniacid" => $uniacid));
		}
		$url = $_W['attachurl'];
		$arr = array("url" => $url, "pro_list" => $pro_list,"count" => count($pro_list));
		echo json_encode($arr);
	}

	public function doMobiledoWelfare()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$id = $_GPC['id'];
		if (!empty($id)) {
			$where = 'and class_id=' . $id;
		}
		$pro_lists = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid ' . $where . ' ORDER BY pro_id DESC LIMIT 20 ', array(":uniacid" => $uniacid));
		$pro_list = array();
		foreach ($pro_lists as $k) {
			$class_name = pdo_fetch('SELECT class_name  FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid = :uniacid AND class_id = :class_id', array(":uniacid" => $uniacid, ":class_id" => $k['class_id']));
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$fund_totals = floatval($money_totals['total']);
			$rows = array("pro_id" => $k['pro_id'], "class_name" => $class_name['class_name'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($fund_totals), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_rate" => round(floatval($fund_totals) / $k['pro_goal'], 5) * 100);
			array_push($pro_list, $rows);
		}
		$url = $_W['attachurl'];
		$arr = array("url" => $url, "pro_list" => $pro_list);
		echo json_encode($arr);
	}
	public function doMobileHome()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$mem_id = $this->checkuser();
		$user = pdo_fetch('SELECT mem_name,mem_photo FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $mem_id));
		$user_name = $user['mem_name'];
		$user_photo = $user['mem_photo'];
		$sql = 'SELECT sum(f.fund_value) as sum,count(distinct f.pro_id) as count FROM ' . tablename('tim_welfare_member') . ' m
			left join ' . tablename('tim_welfare_fund') . ' f on f.mem_id=m.mem_id and f.fund_true=:fund_true
			WHERE m.uniacid=:uniacid and m.mem_id = :mem_id';
		$params = array(":fund_true" => true, ":uniacid" => $uniacid, ":mem_id" => $mem_id);
		$list = pdo_fetch($sql, $params);
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid = :uniacid', array(":uniacid" => $uniacid));
		$adv = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_adv') . ' WHERE uniacid=:uniacid AND position=:position', array(":uniacid" => $uniacid, ":position" => "2"));
		$title = '个人主页';
		include $this->template('home');
	}
	public function checkuser()
	{
		global $_W, $_GPC;
		$fans = mc_oauth_userinfo();
		$uniacid = $_W['uniacid'];
		$user_name = $fans['nickname'];
		$user_photo = $fans['avatar'];
		$openid = $fans['openid'];
		if (!empty($openid)) {
			$user = pdo_fetch('SELECT mem_id FROM ' . tablename('tim_welfare_member') . ' WHERE openid=:openid', array(":openid" => $openid));
			$data = array("uniacid" => $uniacid, "openid" => $openid, "mem_name" => $user_name, "mem_photo" => $user_photo, "mem_pass" => "");
			if (empty($user)) {
				pdo_insert('tim_welfare_member', $data);
				$mem_id = pdo_insertid();
			} else {
				pdo_update('tim_welfare_member', array("mem_name" => $user_name, "mem_photo" => $user_photo), array("openid" => $openid));
				$mem_id = $user['mem_id'];
			}
		}
		return $mem_id;
	}
	public function doMobileUadd()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$mem_id = $this->checkuser();
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid = :uniacid', array(":uniacid" => $uniacid));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;
		$add_record = pdo_fetchall('SELECT u.*,p.pro_id FROM ' . tablename('tim_welfare_uadd') . ' u 
		left join  ' . tablename(tim_welfare_project) . ' p on u.pro_name=p.pro_name
		WHERE mem_id=:mem_id  ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(":mem_id" => $mem_id));
		if ($_GPC['flag'] == 1) {
			$html = '';
			foreach ($add_record as $k) {
				$pros = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_name=:pro_name', array(":pro_name" => $k['pro_name']));
				if ($k['verify'] == true) {
					$class = 'i_d_5_1_r';
					$state = '审核通过';
					$url = $this->createMobileUrl('per', array("pro_id" => $pros['pro_id']));
				} else {
					$class = 'i_d_5_1_r2';
					$state = '未审核';
					$url = 'javascript:;';
				}
				$html .= '<div class=\'i_d_5_1\'><a href=\'' . $url . '\'><p class=\'gy1_p1\'>' . mb_substr($k['pro_name'], 0, 12, 'utf-8') . '</p><div class=\'i_d_5_1_l\'>' . date('Y-m-d H:i:s', $k['add_time']) . '</div><div class=\'' . $class . '\'><p>' . $state . '</p></div><div class=\'clearfix\'></div></a></div>';
			}
			return $html;
			exit;
		}
		include $this->template('uadd');
	}
	public function doMobilePer()
	{
		global $_W, $_GPC;
		$this->checkuser();
		$uniacid = $_W['uniacid'];
		$pro_id = $_GPC['pro_id'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$adv = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_adv') . ' WHERE uniacid=:uniacid AND position=:position', array(":uniacid" => $uniacid, ":position" => "1"));
		$per_pro = pdo_fetch('SELECT p.*,c.name,c.phone,c.content,c.company_name,c.company_img FROM ' . tablename('tim_welfare_project') . ' p left join ' . tablename('tim_welfare_company') . ' c on p.company_id=c.company_id WHERE p.uniacid=:uniacid AND p.pro_id=:pro_id', array(":uniacid" => $uniacid, ":pro_id" => $pro_id));
		$per_count = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id AND fund_true=:fund_true', array(":pro_id" => $pro_id, ":fund_true" => true));
		$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $pro_id, ":fund_true" => true, ":type" => "MONEY"));
		$per_pro['pro_fund'] = floatval($money_totals['total']);
		$title = $per_pro['pro_name'];
		$_share = $_GPC['share'];
		$com_list = array();
		$comments = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_comment') . ' WHERE pro_id=:pro_id and parent_id=:parent_id and state=1 order by comment_id desc limit 0,5', array(":pro_id" => $pro_id, ":parent_id" => 0));
		foreach ($comments as $k) {
			$user = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $k['mem_id']));
			$son_comment = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_comment') . ' WHERE pro_id=:pro_id and parent_id=:parent_id and state=1 order by comment_id desc', array(":pro_id" => $pro_id, ":parent_id" => intval($k['comment_id'])));
			$son_list = array();
			foreach ($son_comment as $v) {
				$u = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => intval($v['mem_id'])));
				if (empty($u['mem_name'])) {
					$u['mem_name'] = '管理员';
				}
				$rows = array("comment_id" => $v['comment_id'], "pro_id" => $v['pro_id'], "parent_id" => $v['parent_id'], "mem_name" => $u['mem_name'], "mem_photo" => $u['mem_photo'], "comment_cont" => $v['comment_cont'], "time" => $v['time']);
				array_push($son_list, $rows);
			}
			$row_data = array("comment_id" => $k['comment_id'], "pro_id" => $k['pro_id'], "parent_id" => $k['parent_id'], "mem_name" => $user['mem_name'], "mem_photo" => $user['mem_photo'], "comment_cont" => $k['comment_cont'], "time" => $k['time'], "son_list" => $son_list);
			array_push($com_list, $row_data);
		}
		if ($set['is_sort'] == true) {
			$list_arr = pdo_fetchall('SELECT sum(f.fund_value) as fund_value,f.type,m.mem_name,m.mem_photo FROM ' . tablename('tim_welfare_fund') . ' f 
				left join ' . tablename('tim_welfare_member') . ' m	on f.mem_id=m.mem_id
				WHERE f.pro_id=:pro_id AND f.fund_true=:fund_true group by f.mem_id order by sum(f.fund_value) desc limit 0,10', array(":pro_id" => $pro_id, ":fund_true" => true));
		} else {
			$list_arr = pdo_fetchall('SELECT f.fund_value,f.fund_time,f.type,m.mem_name,m.mem_photo FROM ' . tablename('tim_welfare_fund') . ' f 
				left join ' . tablename('tim_welfare_member') . ' m	on f.mem_id=m.mem_id
				WHERE f.pro_id=:pro_id AND f.fund_true=:fund_true order by f.fund_time desc limit 0,10', array(":pro_id" => $pro_id, ":fund_true" => true));
		}
		$my_id = $this->checkuser();
		$my_name = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $my_id));
		include $this->template('details');
	}
	public function doMobileMorecomment()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$pindex = max(1, intval($_GPC['page']));
		$psize = 5;
		$pro_id = $_GPC['pro_id'];
		$com_list = array();
		$comments = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_comment') . ' WHERE pro_id=:pro_id and parent_id=:parent_id and state=1 order by comment_id desc', array(":pro_id" => $pro_id, ":parent_id" => 0));
		foreach ($comments as $k) {
			$user = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $k['mem_id']));
			$son_comment = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_comment') . ' WHERE pro_id=:pro_id and parent_id=:parent_id and state=1 order by comment_id desc', array(":pro_id" => $pro_id, ":parent_id" => intval($k['comment_id'])));
			$son_list = array();
			foreach ($son_comment as $v) {
				$u = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => intval($v['mem_id'])));
				$rows = array("comment_id" => $v['comment_id'], "pro_id" => $v['pro_id'], "parent_id" => $v['parent_id'], "mem_name" => $u['mem_name'], "mem_photo" => $u['mem_photo'], "comment_cont" => $v['comment_cont'], "time" => $v['time']);
				array_push($son_list, $rows);
			}
			$row_data = array("comment_id" => $k['comment_id'], "pro_id" => $k['pro_id'], "parent_id" => $k['parent_id'], "mem_name" => $user['mem_name'], "mem_photo" => $user['mem_photo'], "comment_cont" => $k['comment_cont'], "time" => $k['time'], "son_list" => $son_list);
			array_push($com_list, $row_data);
		}
		$com_list_arr = array_slice($com_list, ($pindex - 1) * $psize, $psize);
		$html = '';
		foreach ($com_list_arr as $row) {
			$html .= '<div class=\'i_d_5\'>
				  	<div class=\'i_d_5_1\' style=\'height:auto;padding-left:0;padding-right:5px;\'>
					    <div class=\'i_d_5_1_l\' style=\'width:20%\'>
					    	<img src=\'' . $row['mem_photo'] . '\' style=\'width:50px;border-radius:50%;float:left;margin-top:0;\'>
					    </div>
					    <div style=\'float:left;width:80%\'>
							<p style=\'color:#b1a8a3;margin-bottom:3px\'>' . $row['mem_name'] . '</p>
					    	<p style=\'margin-bottom:5px;\'>' . $row['comment_cont'] . '</p>
					    	<p style=\'float:left;color:#b1a8a3;margin-bottom:3px\'>' . date('Y-m-d H:i:s', $row['time']) . '</p>
					    	<a href=\'' . $this->createMobileUrl('comment', array("pro_id" => $pro_id, "parent_id" => $row['comment_id'])) . '\'><p style=\'float:right;padding-left:25px;background:url(' . MODULE_URL . 'template/mobile/img/comment.png) no-repeat 0 -27px;background-size:26px;\'>回复</p></a>';
			if (!empty($row['son_list'])) {
				$html .= '<div class=\'respond-list\' style=\'background-color:#f3f2f1;height:auto;clear:both;padding:8px;border-radius:5px\'>
					    	';
				foreach ($row['son_list'] as $k) {
					$html .= '<p><span style=\'color:#b1a8a3;\'>' . $k['mem_name'] . '：</span>' . $k['comment_cont'] . '</p>';
				}
				$html .= '</div>';
			}
			$html .= '</div><div class=\'clear\'></div></div></div>';
		}
		return $html;
	}
	public function doMobileComment()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$pro_id = intval($_GPC['pro_id']);
		$parent_id = intval($_GPC['parent_id']);
		$mem_id = $this->checkuser();
		include $this->template('comment');
	}
	public function doMobileCommentsub()
	{
		global $_W, $_GPC;
		$pro_id = intval($_GPC['pro_id']);
		$parent_id = intval($_GPC['parent_id']);
		$mem_id = intval($_GPC['mem_id']);
		$comment_cont = $_GPC['comment_cont'];
		$data = array("parent_id" => $parent_id, "pro_id" => $pro_id, "mem_id" => $mem_id, "comment_cont" => $comment_cont, "state" => 0, "time" => time());
		pdo_insert('tim_welfare_comment', $data);
		$url = $this->createMobileUrl('per', array("pro_id" => $pro_id)) . '#comment-list';
		header("Location: {$url}");
	}
	public function doMobileCat()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$class_id = $_GPC['class_id'];
		$class_name = $_GPC['class_name'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 5;
		$class_pros = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid AND class_id=:class_id ORDER BY pro_id ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(":uniacid" => $uniacid, ":class_id" => $class_id));
		$class_pro = array();
		foreach ($class_pros as $k) {
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$rows = array("pro_id" => $k['pro_id'], "class_id" => $k['class_id'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($money_totals['total']), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_rate" => round(floatval($fund_totals['total']) / $k['pro_goal'], 5) * 100);
			array_push($class_pro, $rows);
		}
		$title = $class_name;
		include $this->template('category');
	}
	public function doMobileCatmonth()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$class_name = $_GPC['class_name'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$cls = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid=:uniacid and class_name=:class_name', array(":uniacid" => $uniacid, ":class_name" => $class_name));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 5;
		$class_pros = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid AND class_id=:class_id ORDER BY pro_id ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(":uniacid" => $uniacid, ":class_id" => $cls['class_id']));
		$class_pro = array();
		foreach ($class_pros as $k) {
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$rows = array("pro_id" => $k['pro_id'], "class_id" => $k['class_id'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($money_totals['total']), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_rate" => round(floatval($fund_totals['total']) / $k['pro_goal'], 5) * 100);
			array_push($class_pro, $rows);
		}
		$title = $class_name;
		include $this->template('category');
	}
	public function doMobileCatdone()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$class_id = $_GPC['class_id'];
		$class_name = $_GPC['class_name'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 5;
		$class_pros = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid AND class_id=:class_id AND pro_fund>=pro_goal ORDER BY pro_id ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(":uniacid" => $uniacid, ":class_id" => $class_id));
		$class_pro = array();
		foreach ($class_pros as $k) {
			$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
			$rows = array("pro_id" => $k['pro_id'], "class_id" => $k['class_id'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($money_totals['total']), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_rate" => round(floatval($fund_totals['total']) / $k['pro_goal'], 5) * 100);
			array_push($class_pro, $rows);
		}
		$title = $class_name;
		include $this->template('category');
	}
	public function doWebActivity()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ('post' == $op) {
			$pro_id = intval($_GPC['pro_id']);
			$class = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
			$company = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_company') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
			if (!empty($pro_id)) {
				$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' where uniacid=:uniacid AND pro_id=:pro_id', array(":uniacid" => $uniacid, ":pro_id" => $pro_id));
				$fund_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true', array(":pro_id" => $pro_id, ":fund_true" => true));
				$item['pro_fund'] = floatval($fund_totals['total']);
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			if (checksubmit('submit')) {
				empty($_GPC['pro_name']) ? message('亲,标题不能为空') : ($pro_name = $_GPC['pro_name']);
				$class_id = $_GPC['class_id'];
				$pro_short = $_GPC['pro_short'];
				$pro_feature = $_GPC['pro_feature'];
				$pro_gress = $_GPC['pro_gress'];
				$pro_content = $_GPC['pro_content'];
				$pro_fund = $_GPC['pro_fund'];
				$pro_goal = $_GPC['pro_goal'];
				$company_id = $_GPC['company_id'];
				$starttime = strtotime($_GPC['starttime']);
				$endtime = strtotime($_GPC['endtime']);
				$pro_stick = $_GPC['pro_stick'];
				$pro_uber = $_GPC['pro_uber'];
				$data = array("pro_id" => $pro_id, "uniacid" => $uniacid, "class_id" => $class_id, "pro_name" => $pro_name, "pro_short" => $pro_short, "pro_gress" => $pro_gress, "pro_feature" => $pro_feature, "pro_content" => $pro_content, "pro_fund" => $pro_fund, "pro_goal" => $pro_goal, "company_id" => $company_id, "starttime" => $starttime, "endtime" => $endtime, "pro_stick" => $pro_stick, "pro_uber" => $pro_uber);
				if (empty($pro_id)) {
					pdo_insert('tim_welfare_project', $data);
					message('数据添加成功！', $this->createWebUrl('activity', array("op" => "display")), 'success');
				} else {
					pdo_update('tim_welfare_project', $data, array("pro_id" => $pro_id));
					message('数据更新成功！', $this->createWebUrl('activity', array("op" => "display")), 'success');
				}
			} else {
				include $this->template('activity');
			}
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_project') . '  where pro_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$pro_id = intval($_GPC['pro_id']);
				$row = pdo_fetch('SELECT pro_id FROM ' . tablename('tim_welfare_project') . ' WHERE pro_id = :pro_id', array(":pro_id" => $pro_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('activity', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_project', array("pro_id" => $pro_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid ORDER BY pro_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$lists = pdo_fetchall($sql, $params);
					$list = array();
					foreach ($lists as $k) {
						$class_name = pdo_fetch('SELECT class_name  FROM ' . tablename('tim_welfare_class') . 'WHERE uniacid=:uniacid AND class_id = :class_id', array(":uniacid" => $uniacid, ":class_id" => $k['class_id']));
						$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $k['pro_id'], ":fund_true" => true, ":type" => "MONEY"));
						$rows = array("pro_id" => $k['pro_id'], "class_name" => $class_name['class_name'], "pro_name" => $k['pro_name'], "pro_short" => $k['pro_short'], "pro_feature" => $k['pro_feature'], "pro_content" => $k['pro_content'], "pro_fund" => floatval($money_totals['total']), "pro_goal" => $k['pro_goal'], "pro_stick" => $k['pro_stick'], "pro_uber" => $k['pro_uber']);
						array_push($list, $rows);
					}
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('activity');
				}
			}
		}
	}
	public function doWebCategory()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ('post' == $op) {
			$class_id = intval($_GPC['class_id']);
			if (!empty($class_id)) {
				$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_class') . ' where class_id=:class_id', array(":class_id" => $class_id));
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			if (checksubmit('submit')) {
				empty($_GPC['class_name']) ? message('亲,标题不能为空') : ($class_name = $_GPC['class_name']);
				$class_id = $_GPC['class_id'];
				$data = array("uniacid" => $uniacid, "class_id" => $class_id, "class_name" => $class_name);
				if (empty($class_id)) {
					pdo_insert('tim_welfare_class', $data);
					message('数据添加成功！', $this->createWebUrl('category', array("op" => "display")), 'success');
				} else {
					pdo_update('tim_welfare_class', $data, array("class_id" => $class_id));
					message('数据更新成功！', $this->createWebUrl('category', array("op" => "display")), 'success');
				}
			} else {
				include $this->template('category');
			}
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_class') . '  where class_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$class_id = intval($_GPC['class_id']);
				$row = pdo_fetch('SELECT class_id FROM ' . tablename('tim_welfare_class') . ' WHERE class_id = :class_id', array(":class_id" => $class_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('category', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_class', array("class_id" => $class_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT * FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid=:uniacid ORDER BY class_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('category');
				}
			}
		}
	}
	public function doWebFund()
	{
		global $_W, $_GPC;
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ('display' == $op) {
			$pro_id = $_GPC['pro_id'];
			$uniacid = $_W['uniacid'];
			$pindex = max(1, intval($_GPC['page']));
			$psize = 10;
			$sql = 'SELECT * FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id AND fund_true=:fund_true ORDER BY fund_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
			$params = array(":pro_id" => $pro_id, ":fund_true" => true);
			$lists = pdo_fetchall($sql, $params);
			$list = array();
			foreach ($lists as $k) {
				$mem_name = pdo_fetch('SELECT *  FROM ' . tablename('tim_welfare_member') . 'WHERE mem_id = :mem_id', array(":mem_id" => $k['mem_id']));
				$pro_name = pdo_fetch('SELECT pro_name  FROM ' . tablename('tim_welfare_project') . 'WHERE pro_id = :pro_id', array(":pro_id" => $k['pro_id']));
				$rows = array("fund_id" => $k['fund_id'], "pro_name" => $pro_name['pro_name'], "mem_photo" => $mem_name['mem_photo'], "mem_name" => $mem_name['mem_name'], "order_num" => $k['order_num'], "fund_value" => $k['fund_value'], "fund_time" => $k['fund_time'], "type" => $k['type']);
				array_push($list, $rows);
			}
			$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id AND fund_true=:fund_true', array(":pro_id" => $pro_id, ":fund_true" => true));
			$pager = pagination($total, $pindex, $psize);
			include $this->template('fund');
		}
		if ('del' == $op) {
			if (isset($_GPC['delete'])) {
				$ids = implode(',', $_GPC['delete']);
				$sqls = 'delete from  ' . tablename('tim_welfare_fund') . '  where fund_id in(' . $ids . ')';
				pdo_query($sqls);
				message('删除成功！', referer(), 'success');
			}
			$fund_id = intval($_GPC['fund_id']);
			$row = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_fund') . ' WHERE `fund_id` = :fund_id', array(":fund_id" => $fund_id));
			if (empty($row)) {
				message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('fund', array("op" => "display")), 'error');
			}
			pdo_delete('tim_welfare_fund', array("fund_id" => $fund_id));
			message('删除成功！', referer(), 'success');
		}
	}
	public function doWebSlide()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ('post' == $op) {
			$slide_id = intval($_GPC['slide_id']);
			if (!empty($slide_id)) {
				$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_slide') . ' where slide_id=:slide_id', array(":slide_id" => $slide_id));
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			if (checksubmit('submit')) {
				empty($_GPC['slide_title']) ? message('亲,标题不能为空') : ($slide_title = $_GPC['slide_title']);
				$slide_pic = $_GPC['slide_pic'];
				$slide_url = $_GPC['slide_url'];
				$xh = $_GPC['xh'];
				$data = array("uniacid" => $uniacid, "slide_id" => $slide_id, "slide_title" => $slide_title, "slide_pic" => $slide_pic, "slide_url" => $slide_url, "xh" => $xh);
				if (empty($slide_id)) {
					pdo_insert('tim_welfare_slide', $data);
					message('数据添加成功！', $this->createWebUrl('slide', array("op" => "display")), 'success');
				} else {
					pdo_update('tim_welfare_slide', $data, array("slide_id" => $slide_id));
					message('数据更新成功！', $this->createWebUrl('slide', array("op" => "display")), 'success');
				}
			} else {
				include $this->template('slide');
			}
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_slide') . '  where slide_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$slide_id = intval($_GPC['slide_id']);
				$row = pdo_fetch('SELECT slide_id FROM ' . tablename('tim_welfare_slide') . ' WHERE slide_id = :slide_id', array(":slide_id" => $slide_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('slide', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_slide', array("slide_id" => $slide_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT * FROM ' . tablename('tim_welfare_slide') . ' WHERE uniacid=:uniacid ORDER BY slide_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_slide') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('slide');
				}
			}
		}
	}
	public function doWebAdv()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ('post' == $op) {
			$adv_id = intval($_GPC['adv_id']);
			if (!empty($adv_id)) {
				$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_adv') . ' where adv_id=:adv_id', array(":adv_id" => $adv_id));
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			if (checksubmit('submit')) {
				empty($_GPC['adv_title']) ? message('亲,标题不能为空') : ($adv_title = $_GPC['adv_title']);
				$adv_pic = $_GPC['adv_pic'];
				$adv_link = $_GPC['adv_link'];
				$position = $_GPC['position'];
				$data = array("uniacid" => $uniacid, "adv_title" => $adv_title, "adv_pic" => $adv_pic, "adv_link" => $adv_link, "position" => $position);
				if (empty($adv_id)) {
					pdo_insert('tim_welfare_adv', $data);
					message('数据添加成功！', $this->createWebUrl('adv', array("op" => "display")), 'success');
				} else {
					pdo_update('tim_welfare_adv', $data, array("adv_id" => $adv_id));
					message('数据更新成功！', $this->createWebUrl('adv', array("op" => "display")), 'success');
				}
			} else {
				include $this->template('adv');
			}
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_adv') . '  where adv_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$adv_id = intval($_GPC['adv_id']);
				$row = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_adv') . ' WHERE adv_id = :adv_id', array(":adv_id" => $adv_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('adv', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_adv', array("adv_id" => $adv_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT * FROM ' . tablename('tim_welfare_adv') . ' WHERE uniacid=:uniacid ORDER BY adv_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_adv') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('adv');
				}
			}
		}
	}
	public function doWebProj()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		load()->func('tpl');
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ('post' == $op) {
			$id = intval($_GPC['id']);
			if (!empty($id)) {
				$sql = 'SELECT t1.*,t3.class_name FROM ' . tablename('tim_welfare_uadd') . 't1 					
					left join ' . tablename('tim_welfare_class') . 't3 on t1.class_id=t3.class_id 
					WHERE t1.id=:id';
				$params = array(":id" => $id);
				$item = pdo_fetch($sql, $params);
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			include $this->template('proj');
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_uadd') . '  where id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$id = intval($_GPC['id']);
				$row = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_uadd') . ' WHERE `id` = :id', array(":id" => $id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('proj', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_uadd', array("id" => $id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT t1.*,t2.mem_photo,t2.mem_name,t3.class_name FROM ' . tablename('tim_welfare_uadd') . 't1 
					left join ' . tablename('tim_welfare_member') . 't2 on t1.mem_id=t2.mem_id 
					left join ' . tablename('tim_welfare_class') . 't3 on t1.class_id=t3.class_id 
					WHERE t1.verify=:verify and t3.uniacid=:uniacid ORDER BY t1.id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":verify" => false, ":uniacid" => $uniacid);
					$lists = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_uadd'));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('proj');
				}
			}
		}
	}
	public function doWebVerify()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$id = $_GPC['id'];
		pdo_update('tim_welfare_uadd', array("verify" => true), array("id" => $id));
		$pros = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_uadd') . ' WHERE id = :id', array(":id" => $id));
		$data = array("uniacid" => $uniacid, "class_id" => $pros['class_id'], "pro_name" => $pros['pro_name'], "pro_short" => $pros['pro_short'], "pro_gress" => $pros['pro_gress'], "pro_feature" => $pros['pro_feature'], "pro_content" => $pros['pro_content'], "pro_fund" => 0, "pro_goal" => $pros['pro_goal']);
		pdo_insert('tim_welfare_project', $data);
		message('项目审核成功！', $this->createWebUrl('proj'), 'success');
	}
	public function doWebParam_set()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		load()->func('tpl');
		$info = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE `uniacid` = :uniacid', array(":uniacid" => $uniacid));
		if (checksubmit('submit')) {
			$appid = $_GPC['appid'];
			$appsecret = $_GPC['appsecret'];
			$mchid = $_GPC['mchid'];
			$shkey = $_GPC['shkey'];
			$gy_name = $_GPC['gy_name'];
			$gy_logo = $_GPC['gy_logo'];
			$is_follow = $_GPC['is_follow'];
			$follow_url = $_GPC['follow_url'];
			$is_sort = $_GPC['is_sort'];
			$type = 'MONEY';
			$ratio = $_GPC['ratio'];
			$template_id = $_GPC['template_id'];
			$gy_agree_name = $_GPC['gy_agree_name'];
			$gy_agree = $_GPC['gy_agree'];
			$infos = array("appid" => $appid, "appsecret" => $appsecret, "mchid" => $mchid, "shkey" => $shkey, "uniacid" => $uniacid, "gy_name" => $gy_name, "gy_logo" => $gy_logo, "is_follow" => $is_follow, "follow_url" => $follow_url, "is_sort" => $is_sort, "type" => $type, "ratio" => $ratio, "template_id" => $template_id, "gy_agree_name" => $gy_agree_name, "gy_agree" => $gy_agree, "cash1" => $_GPC['cash1'], "cash2" => $_GPC['cash2'], "cash3" => $_GPC['cash3'], "cash4" => $_GPC['cash4']);
			if (empty($info)) {
				pdo_insert('tim_welfare_set', $infos);
				message('数据添加成功！', $this->createWebUrl('param_set'), 'success');
			} else {
				$id = $info['id'];
				pdo_update('tim_welfare_set', $infos, array("id" => $id));
				message('数据更新成功！', $this->createWebUrl('param_set'), 'success');
			}
		}
		include $this->template('param_set');
	}
	public function doMobileAgree()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE `uniacid` = :uniacid', array(":uniacid" => $uniacid));
		include $this->template('agree');
	}
	public function doMobileDonate()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$fund_value = floatval($_GPC['price']);
		$pro_id = $_GPC['pro_id'];
		$ch = $_GPC['ch'];
		$mem_id = $this->checkuser();
		
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$donate = array("pro_id" => $pro_id, "mem_id" => $mem_id, "order_num" => "", "fund_value" => $fund_value, "fund_time" => time(), "fund_true" => false, "type" => "MONEY");
		if ($donate['fund_value'] > 0) {
			$result = pdo_insert('tim_welfare_fund', $donate);
		}
		if (!empty($result)) {
			$fund_id = pdo_insertid();
		}

		$user = pdo_fetch('SELECT mem_name FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $mem_id));
		$pro_now = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_id=:pro_id', array(":pro_id" => $pro_id));
		$good_name = mb_substr($pro_now['pro_name'], 0, 15, 'utf-8');
		$params['tid'] = $this->getTid($fund_id, $mem_id);
		$params['ordersn'] = $this->getOrderNo($fund_id, $mem_id);
		$params['title'] = $good_name;
		$params['fee'] = $fund_value;
		$params['user'] = $user['mem_name'];
		
		pdo_update('tim_welfare_fund', array("order_num" => $params['tid']), array("fund_id" => $fund_id));
		$module = 'tim_welfare';
		$moduels = uni_modules();
		if (empty($params) || !array_key_exists($module, $moduels)) {
			message('访问错误.');
			exit;
		}
		$setting = uni_setting($_W['uniacid'], 'payment');
		// print_r($donate);
		// exit;
		$sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid';
		$pars = array();
		$pars[':uniacid'] = $_W['uniacid'];
		$pars[':module'] = $module;
		$pars[':tid'] = $params['tid'];
		$log = pdo_fetch($sql, $pars);
		
		if (empty($log)) {
			$moduleid = pdo_fetchcolumn('SELECT mid FROM ' . tablename('modules') . ' WHERE name = :name', array(":name" => $module));
			$moduleid = empty($moduleid) ? '000000' : sprintf('%06d', $moduleid);
			$uniontid = date('YmdHis') . $moduleid . random(8, 1);
			$log = array("uniacid" => $_W['uniacid'], "acid" => $_W['acid'], "openid" => $_W['member']['uid'], "module" => $this->module['name'], "tid" => $params['tid'], "fee" => $params['fee'], "card_fee" => $params['fee'], "card_type" => "0", "card_id" => "0", "status" => "0", "type" => "wechat", "is_usecard" => "0", "uniontid" => $uniontid);
			pdo_insert('core_paylog', $log);
			$log['tid'] = pdo_insertid();
		}
		
		if (!empty($log) && $log['status'] != '0') {
			message('这个订单已经支付成功, 不需要重复支付.');
		}
		$ps = array();
		$ps['tid'] = $log['tid'];
		$ps['uniontid'] = $log['uniontid'];
		$ps['user'] = $_W['fans']['from_user'];
		$ps['fee'] = $log['card_fee'];
		$ps['title'] = $params['title'];
		
		load()->model('payment');
		load()->func('communication');
		$sl = base64_encode(json_encode($ps));
		$auth = sha1($sl . $_W['uniacid'] . $_W['config']['setting']['authkey']);
		header("location: ../payment/wechat/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}&fund_id={$fund_id}&pro_id={$pro_id}");
	}
	public function getTid($fund_id, $mem_id)
	{
		return date('YmdHis', time()) . $fund_id . $mem_id;
	}
	public function getOrderNo($fund_id, $mem_id)
	{
		return date('YmdHis', time()) . 'f' . $fund_id . 'u' . $mem_id;
	}
	public function payResult($params)
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$order = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_fund') . ' WHERE order_num=:order_num', array(":order_num" => $params['tid']));
		$fund_id = intval($order['fund_id']);
		$fund_value = floatval($params['fee']);
		$order_num = $order['order_num'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pros = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_id=:pro_id', array(":pro_id" => $order['pro_id']));
		$fund_values = floatval($pros['pro_fund']) + floatval($order['fund_value']);
		if ($params['result'] == 'success' && $params['from'] == 'notify') {
			pdo_update('tim_welfare_fund', array("fund_true" => true, "order_num" => $order_num), array("fund_id" => $fund_id));
			pdo_update('tim_welfare_project', array("pro_fund" => $fund_values), array("pro_id" => $order['pro_id']));
		}
		if ($params['from'] == 'return') {
			if ($params['result'] == 'success') {
				pdo_update('tim_welfare_fund', array("fund_true" => true, "order_num" => $order_num), array("fund_id" => $fund_id));
				pdo_update('tim_welfare_project', array("pro_fund" => $fund_values), array("pro_id" => $order['pro_id']));
				$url = $this->createMobileUrl('per', array("pro_id" => $order['pro_id']));
				$_share = array("title" => '我支持了' . $pros['pro_name'] . '公益活动' . $fund_value . '元，TA需要帮助，大家一起来帮帮忙吧，一分钱也是爱！', "link" => $_W['siteroot'] . $url, "imgUrl" => $pros['pro_feature'], "content" => $pros['pro_short']);
				$urls = $this->createMobileUrl('per', array("pro_id" => $order['pro_id'], "share" => $_share));
				$http = $_W['siteroot'] . 'app/' . $urls;
				header("Location: {$http}");
			} else {
				message('捐款失败！', $this->createMobileUrl('per', array("pro_id" => $order['pro_id'])), 'error');
			}
		}
	}
	public function doMobileInvite()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$pro_id = $_GPC['pro_id'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$project = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_id=:pro_id', array(":pro_id" => $pro_id));
		$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $pro_id, ":fund_true" => true, ":type" => "MONEY"));
		$fund_totals['total'] = floatval($money_totals['total']);
		include $this->template('invite');
	}
	public function doMobileInvitenext()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$mem_id = $this->checkuser();
		$user = pdo_fetch('SELECT mem_name,mem_photo,mem_id FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $mem_id));
		$user_name = $user['mem_name'];
		$user_photo = $user['mem_photo'];
		$pro_id = $_GPC['pro_id'];
		$goal = $_GPC['goal'];
		$kouhao = $_GPC['kouhao'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$project = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_id=:pro_id', array(":pro_id" => $pro_id));
		$money_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true and type=:type', array(":pro_id" => $pro_id, ":fund_true" => true, ":type" => "MONEY"));
		$fund_totals['total'] = floatval($money_totals['total']);


		//分享后共捐款
		$gift_id = $_GPC['gift_id'];

		if (!empty($gift_id)) {
			$gift_jk_sql = 'SELECT sum(fund_value) as sum FROM '. tablename('tim_welfare_fund') .' WHERE fund_true = 1 and pro_id = '.$pro_id.' and gift_id = '.$gift_sql;
			$gift_jk_query = pdo_fetch($gift_jk_sql, $params);
		}
		
		

		include $this->template('invite_next');
	}
	public function doMobileShare()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		mc_oauth_userinfo();
		$user_name = $_W['fans']['tag']['nickname'];
		$user_photo = $_W['fans']['tag']['avatar'];
		$openid = $_W['fans']['tag']['openid'];
		$mem_id = $_GPC['mem_id'];
		$pro_id = $_GPC['pro_id'];
		$goal = $_GPC['goal'];
		$kouhao = $_GPC['kouhao'];
		$gift_id = $_GPC['gift_id'];
		$other_id = $this->checkuser();
		$users = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE mem_id=:mem_id', array(":mem_id" => $mem_id));
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$project = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE pro_id=:pro_id', array(":pro_id" => $pro_id));
		$fund_totals = pdo_fetch('SELECT sum(fund_value) as total FROM ' . tablename('tim_welfare_fund') . ' WHERE pro_id=:pro_id and fund_true=:fund_true', array(":pro_id" => $pro_id, ":fund_true" => true));

		//共募善款
		$params = array(":mem_id" => $mem_id);
		$gifts = array(":gift_id" => $gift_id,":pro_id" => $pro_id);
		// $mem_sql = 'select mem_id FROM ' . tablename('tim_welfare_gift') . ' WHERE other_id = :mem_id GROUP BY mem_id';
		// $gift_sql = 'select gift_id FROM ' . tablename('tim_welfare_gift') . ' WHERE gift_id = '.$gift_id.' or gfid = '.$gift_id;
		$gift_jk_sql = 'SELECT sum(fund_value) as sum FROM '. tablename('tim_welfare_fund') .' WHERE fund_true = 1 and pro_id = :pro_id and gift_id = :gift_id';
		$gift_jk_query = pdo_fetch($gift_jk_sql, $gifts);

		//参与人数
		$gift_hb_sql = 'SELECT * FROM ' . tablename('tim_welfare_fund') . ' 
			WHERE pro_id = '.$pro_id.' and gift_id = '.$gift_id.' GROUP BY mem_id';
		$gift_hb_query = pdo_fetchall($gift_hb_sql, $params);

		//参与用户信息
		$jk_sql = 'SELECT mem_id FROM ' . tablename('tim_welfare_fund') . ' 
			WHERE pro_id = '.$pro_id.' and gift_id = '.$gift_id;
		
		$gift_user_sql = 'SELECT mem_id,mem_name,mem_photo FROM ' .tablename('tim_welfare_member') .'WHERE mem_id in ('.$jk_sql.') ORDER BY mem_id DESC';
		$gift_user_query = pdo_fetchall($gift_user_sql, $params);
		//参与用户捐款流水
		$fund_sql = 'SELECT DISTINCT mem_id,sum(fund_value) as sum,fund_time FROM ' .tablename('tim_welfare_fund') .'WHERE pro_id = '.$pro_id.' and gift_id = '.$gift_id.' ORDER BY mem_id DESC ';
		$fund_query = pdo_fetchall($fund_sql, $params);
		//留言信息
		$gift_message_sql = 'SELECT mem_id,pro_id,comment_cont FROM ' .tablename('tim_welfare_comment') .'WHERE mem_id in ('.$jk_sql.') ORDER BY mem_id DESC';
		$gift_message_query = pdo_fetchall($gift_message_sql, $params);

		$list = array();
		$count_user = '';
		if (!empty($fund_query)) {
				$count_user = count($gift_hb_query);
			for ($i=0; $i < count($gift_user_query); $i++) {
				if (empty($gift_message_query[$i]['comment_cont'])) {
					@$gift_message_query[$i]['comment_cont'] = '';
				}
				$date = date('m-d',$fund_query[$i]['fund_time']);
				$gift_arr = array("mem_name"=>$gift_user_query[$i]['mem_name'],"mem_photo"=>$gift_user_query[$i]['mem_photo'],"mem_id"=>$fund_query[$i]['mem_id'],"sum"=>$fund_query[$i]['sum'],"fund_time"=>$date,"comment_cont"=>$gift_message_query[$i]['comment_cont']);
				array_push($list,$gift_arr);
			}
		}

		//一起捐bgpic and logo
		$logo_sql = 'SELECT logo,bgpic FROM'. tablename('tim_welfare_gift') .'WHERE gift_id = :gift_id';
		$logo_query = pdo_fetch($logo_sql,array(":gift_id" => $gift_id));
		include $this->template('share');
	}
	public function doMobileFundpage()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$mem_id = $this->checkuser();
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;
		$fund_record = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_fund') . ' WHERE mem_id=:mem_id AND fund_true=:fund_true ORDER BY fund_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(":mem_id" => $mem_id, ":fund_true" => true));
		$fund_records = array();
		foreach ($fund_record as $k) {
			$pro_name = pdo_fetch('SELECT pro_name  FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid = :uniacid AND pro_id = :pro_id', array(":uniacid" => $uniacid, ":pro_id" => $k['pro_id']));
			$rows = array("fund_id" => $k['fund_id'], "pro_name" => $pro_name['pro_name'], "pro_id" => $k['pro_id'], "mem_id" => $k['mem_id'], "fund_value" => $k['fund_value'], "fund_time" => $k['fund_time'], "type" => $k['type']);
			array_push($fund_records, $rows);
		}
		$str = '';
		if ($_GPC['flag'] == 1) {
			if (empty($fund_records)) {
				return '';
				exit;
			}
			foreach ($fund_records as $found_rec) {
				$url = $this->createMobileUrl('per', array("pro_id" => $found_rec['pro_id']));
				$pro_name = mb_substr($found_rec['pro_name'], 0, 12, 'utf-8');
				$fund_time = date('Y-m-d H:i:s', $found_rec['fund_time']);
				$fund_value = $found_rec['fund_value'];
				$str .= '<div class="i_d_5"><div class="i_d_5_1" style="height:74px"><a href="' . $url . '"><div class="i_d_5_1_l w65"><p><span class="title1">' . $pro_name . '</span></p><p style="margin-bottom:0px;">' . $fund_time . '</p></div><div class="i_d_5_1_r w34" style="text-align:right;"><p><span style="color:#fe6903; font-size:16px">' . $fund_value . '元</span></p><p style="margin-bottom:0px;"><span class="i_show_cg" style="background:#43ac43;">捐赠成功</span></p></div><div class="clear"></div></a> </div></div>';
			}
			return $str;
			exit;
		}
		include $this->template('fund_list');
	}
	public function doMobileph()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;
		$set = pdo_fetch('SELECT gy_logo,gy_name FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$px = $_GPC['px'];
		if ($px == 1) {
			$s_time = strtotime(date('Y-m-01', strtotime(date('Y-m-d'))));
			$e_time = time();
			$where = '  and f.fund_time >= ' . $s_time . ' and  f.fund_time <= ' . $e_time;
		} else {
			if ($px == 2) {
				$date = date('Y-m-d');
				$first = 1;
				$w = date('w', strtotime($date));
				$now_start = date('Y-m-d', strtotime("{$date} -" . ($w ? $w - $first : 6) . ' days'));
				$s_time = strtotime(date($now_start . ' 00:00:00'));
				$e_time = time();
				$where = '  and f.fund_time >= ' . $s_time . ' and  f.fund_time <= ' . $e_time;
			}
		}
		$sql = 'SELECT sum(f.fund_value) as sum,count(f.fund_value) as count,m.* FROM ' . tablename('tim_welfare_member') . ' m
		left join ' . tablename('tim_welfare_fund') . ' f on f.mem_id=m.mem_id and f.fund_true=:fund_true
		WHERE m.uniacid=:uniacid and m.mem_name <> \'\' ' . $where . ' GROUP BY f.mem_id ORDER BY sum(f.fund_value) DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
		$params = array(":fund_true" => true, ":uniacid" => $uniacid);
		$list = pdo_fetchall($sql, $params);
		$sort_html_one = '';
		if ($_GPC['flag'] == 1) {
			if (empty($list)) {
				return '';
				exit;
			}
			foreach ($list as $row) {
				if (!empty($row['mem_photo'])) {
					if (!empty($row['openid'])) {
						$img = '<img src="' . $row['mem_photo'] . '" style="width:45px;border-radius:5px;float:left;margin-right:15px">';
					} else {
						$img = '<img src="' . tomedia($row['mem_photo']) . '" style="width:45px;border-radius:5px;float:left;margin-right:15px">';
					}
				} else {
					$img = '<img src="' . tomedia($set['gy_logo']) . '" style="width:45px;border-radius:5px;float:left;margin-right:15px">';
				}
				$mem_name = mb_substr($row['mem_name'], 0, 10, 'utf-8');
				$sum = floor($row['sum'] * 100) / 100;
				$sort_html_one .= '<div class=\'i_d_5\'><div class=\'i_d_5_1\' style=\'height:74px\'><div class=\'i_d_5_1_l w70\' style=\'text-align:left;\'>' . $img . '<p style=\'line-height:45px;\'>' . $mem_name . '</p></div><div class=\'i_d_5_1_r w29\' style=\'text-align:right;\'><p><span style=\'color:#fe6903; font-size:16px;line-height:46px;\'>' . $sum . '元</span></p></div><div class=\'clear\'></div></div></div>';
			}
			return $sort_html_one;
			exit;
		}
		include $this->template('ph_list');
	}
	public function doMobileSort()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$pro_id = $_GPC['pro_id'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;
		if ($set['is_sort'] == true) {
			$list_arr = pdo_fetchall('SELECT sum(f.fund_value) as fund_value,f.type,m.mem_name,m.mem_photo FROM ' . tablename('tim_welfare_fund') . ' f 
				left join ' . tablename('tim_welfare_member') . ' m	on f.mem_id=m.mem_id
				WHERE f.pro_id=:pro_id AND f.fund_true=:fund_true group by f.mem_id order by sum(f.fund_value) desc limit ' . ($pindex - 1) * $psize . ',' . $psize, array(":pro_id" => $pro_id, ":fund_true" => true));
			foreach ($list_arr as $k) {
				$fans = $k['fund_value'] . ' 元';
				$sort_html_one .= '<div class=\'i_d_5\'>
					  	<div class=\'i_d_5_1\' style=\'height:74px\'>
						    <div class=\'i_d_5_1_l w70\'>
						    	<img src=\'' . $k['mem_photo'] . '\' style=\'width:45px;border-radius:5px;float:left;margin-right:15px\'>
						    	<p style=\'display: flex;justify-content:center;align-items:Center;\'>' . mb_substr($k['mem_name'], 0, 10, 'utf-8') . '</p>
						    </div>
						    <div class=\'i_d_5_1_r w29\' style=\'text-align:right;\'>
						     	<p><span style=\'color:#fe6903; font-size:16px\'>
										' . $fans . '
								</span></p>
						     	<p style=\'margin-bottom:0px;\'><span class=\'i_show_cg\' style=\'background:#43ac43;\'>累计捐赠</span></p>
						    </div>
						    <div class=\'clear\'></div>
					     </div>
					</div>';
			}
			return $sort_html_one;
		} else {
			$list_arr = pdo_fetchall('SELECT f.fund_value,f.fund_time,f.type,m.mem_name,m.mem_photo FROM ' . tablename('tim_welfare_fund') . ' f 
				left join ' . tablename('tim_welfare_member') . ' m	on f.mem_id=m.mem_id
				WHERE f.pro_id=:pro_id AND f.fund_true=:fund_true order by f.fund_time desc limit ' . ($pindex - 1) * $psize . ',' . $psize, array(":pro_id" => $pro_id, ":fund_true" => true));
			foreach ($list_arr as $k) {
				$fans = $k['fund_value'] . ' 元';
				$sort_html_two .= '<div class=\'i_d_5\'>
					  	<div class=\'i_d_5_1\' style=\'height:74px\'>
						    <div class=\'i_d_5_1_l w70\'>
						    	<img src=\'' . $k['mem_photo'] . '\' style=\'width:40px;border-radius:5px;float:left;margin-right:20px\'>
								<p>' . mb_substr($k['mem_name'], 0, 10, 'utf-8') . '</p>
						    	<p style=\'margin-bottom:0px;\'>' . date('Y-m-d H:i:s', $k['fund_time']) . '</p>
						    </div>
						    <div class=\'i_d_5_1_r w29\' style=\'text-align:right;\'>
						     	<p><span style=\'color:#fe6903; font-size:16px\'>
										' . $fans . '
								</span></p>
						     	<p style=\'margin-bottom:0px;\'><span class=\'i_show_cg\' style=\'background:#43ac43;\'>捐赠成功</span></p>
						    </div>
						    <div class=\'clear\'></div>
					     </div>
					</div>';
			}
			return $sort_html_two;
		}
	}
	private function checkAuth()
	{
		global $_W;
		checkauth();
	}
	private function getUserInfo($access_token, $openid)
	{
		load()->func('communication');
		$api_url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $access_token . '&openid=' . $openid . '&lang=zh_CN';
		$content = ihttp_get($api_url);
		$userInfo = @json_decode($content['content'], true);
		return $userInfo;
	}
	public function doMobileFounder()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$openid = $_W['openid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$classes = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_class') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$user = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_member') . ' WHERE openid=:openid', array(":openid" => $openid));
		load()->func('tpl');
		$company = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_company') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$jssdk = new JSSDK(trim($set['appid']), trim($set['appsecret']));
		$signPackage = $jssdk->GetSignPackage();
		include $this->template('founder');
	}
	public function doMobileComp()
	{
		global $_W, $_GPC;
		$mem_id = $_GPC['mem_id'];
		$class_id = $_GPC['class_id'];
		$pro_name = $_GPC['pro_name'];
		$pro_short = $_GPC['pro_short'];
		$pro_feature = $_GPC['pro_feature'];
		$pro_content = $_GPC['pro_content'];
		$pro_goal = $_GPC['pro_goal'];
		$utel = $_GPC['utel'];
		$data = array("mem_id" => $mem_id, "class_id" => $class_id, "pro_name" => $pro_name, "pro_short" => $pro_short, "pro_gress" => "", "pro_feature" => $pro_feature, "pro_content" => $pro_content, "pro_goal" => $pro_goal, "add_time" => time(), "utel" => $utel);
		pdo_insert('tim_welfare_uadd', $data);
		message('发起成功', $this->createMobileUrl('home'), 'success');
	}
	public function doMobileUpload()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$serverid = $_GPC['serverid'];
		$serverids = explode(',', $serverid);
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$access_token = $this->getAccessToken($set['appid'], $set['appsecret']);
		foreach ($serverids as $key => $value) {
			$content = $this->get_media($access_token, $value);
			$imgname = random(7) . '.jpg';
			file_put_contents(IA_ROOT . '/attachment/' . $imgname, $content);
			$imgnames[] = $imgname;
		}
		return json_encode($imgnames);
	}
	private function get_media($access_token, $media_id)
	{
		$url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=' . $access_token . '&media_id=' . $media_id;
		$content = file_get_contents($url);
		return $content;
	}
	private function getAccessToken($appid, $appsecret)
	{
		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
		$res = json_decode($this->httpGet($url));
		$access_token = $res->access_token;
		return $access_token;
	}
	private function httpGet($url)
	{
		load()->func('communication');
		$result = ihttp_get($url);
		return $result['content'];
	}
	private function get_php_file($filename)
	{
		return file_get_contents($filename);
	}
	private function set_php_file($filename, $content)
	{
		file_put_contents($filename, $content);
	}
	public function doWebFund_download()
	{
		require_once 'fund_download.php';
	}
	public function doWebFund_downloadto()
	{
		require_once 'fund_downloadto.php';
	}
	function encode($value)
	{
		return iconv('utf-8', 'gb2312', $value);
	}
	private function http_request($url, $data = array())
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		$output = curl_exec($ch);
		curl_close($ch);
		return $output;
	}
	private function send_template_message($data)
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$appid = $set['appid'];
		$appsecret = $set['appsecret'];
		$json_token = $this->http_request('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret);
		$access_token = json_decode($json_token, true);
		$this->access_token = $access_token['access_token'];
		$json_template = json_encode($data);
		$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $this->access_token;
		$res = $this->http_request($url, urldecode($json_template));
		return json_encode($res, ture);
	}
	public function doWebCompany()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ('post' == $op) {
			$company_id = $_GPC['company_id'];
			if (!empty($company_id)) {
				$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_company') . ' where uniacid=:uniacid AND company_id=:company_id', array(":uniacid" => $uniacid, ":company_id" => $company_id));
				empty($item) ? message('亲,数据不存在！', '', 'error') : '';
			}
			if (checksubmit('submit')) {
				$company_name = $_GPC['company_name'];
				if (empty($company_name)) {
					message('亲,单位名不能为空');
				}
				$data = array("uniacid" => $uniacid, "company_name" => $company_name, "company_img" => $_GPC['company_img'], "name" => $_GPC['name'], "phone" => $_GPC['phone'], "content" => $_GPC['content'], "add_time" => time());
				if (empty($company_id)) {
					pdo_insert('tim_welfare_company', $data);
					message('数据添加成功！', $this->createWebUrl('company', array("op" => "display")), 'success');
				} else {
					pdo_update('tim_welfare_company', $data, array("company_id" => $company_id));
					message('数据更新成功！', $this->createWebUrl('company', array("op" => "display")), 'success');
				}
			} else {
				include $this->template('company');
			}
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_company') . '  where company_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$company_id = intval($_GPC['company_id']);
				$row = pdo_fetch('SELECT company_id FROM ' . tablename('tim_welfare_company') . ' WHERE company_id = :company_id', array(":company_id" => $company_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('company', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_company', array("company_id" => $company_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT * FROM ' . tablename('tim_welfare_company') . ' WHERE uniacid=:uniacid ORDER BY company_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_company') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('company');
				}
			}
		}
	}
	public function doWebphb()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ($op == 'post') {
			if (checksubmit('submit')) {
				$mem_name = $_GPC['mem_name'];
				if (empty($mem_name)) {
					message('亲,姓名不能为空！');
				}
				$data = array("uniacid" => $uniacid, "mem_name" => $mem_name, "mem_photo" => $_GPC['mem_photo'], "content" => $_GPC['content']);
				pdo_insert('tim_welfare_member', $data);
				message('数据添加成功！', $this->createWebUrl('phb', array("op" => "display")), 'success');
			} else {
				include $this->template('phb');
			}
		} else {
			if ($op == 'del') {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_fund') . '  where fund_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$fund_id = intval($_GPC['fund_id']);
				$row = pdo_fetch('SELECT fund_id FROM ' . tablename('tim_welfare_fund') . ' WHERE fund_id = :fund_id', array(":fund_id" => $fund_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('phb', array("op" => "see")), 'error');
				}
				pdo_delete('tim_welfare_fund', array("fund_id" => $fund_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ($op == 'display') {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$set = pdo_fetch('SELECT gy_logo FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$mem_name = $_GPC['mem_name'];
					if (!empty($mem_name)) {
						$where = ' and m.mem_name like \'%' . $mem_name . '%\'';
					}
					$px = $_GPC['px'];
					if (empty($px) || $px == 1) {
						$order = 'ORDER BY m.mem_id DESC';
					} else {
						if ($px == 2) {
							$order = 'ORDER BY sum(f.fund_value) DESC ,m.mem_id DESC';
						} else {
							if ($px == 3) {
								$order = 'ORDER BY count(f.fund_value) DESC ,m.mem_id DESC';
							}
						}
					}
					$sql = 'SELECT sum(f.fund_value) as sum,count(f.fund_value) as count,m.* FROM ' . tablename('tim_welfare_member') . ' m
			left join ' . tablename('tim_welfare_fund') . ' f on f.mem_id=m.mem_id 
			WHERE m.uniacid=:uniacid and f.fund_true=:fund_true and m.mem_name <> \'\' ' . $where . ' GROUP BY m.mem_id ' . $order . ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":fund_true" => true, ":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(DISTINCT(m.mem_id)) FROM ' . tablename('tim_welfare_member') . ' m 
			left join ' . tablename('tim_welfare_fund') . ' f on f.mem_id=m.mem_id 
			WHERE m.mem_name <> \'\' ' . $where . 'and f.fund_true=:fund_true  and m.uniacid=:uniacid ', array(":fund_true" => true, ":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('phb');
				} else {
					if ($op == 'see') {
						$pindex = max(1, intval($_GPC['page']));
						$psize = 10;
						$mem_id = $_GPC['mem_id'];
						$sql = 'SELECT f.*,p.pro_name FROM ' . tablename('tim_welfare_fund') . ' f
			left join ' . tablename('tim_welfare_project') . ' p on f.pro_id=p.pro_id
			WHERE f.fund_true=:fund_true and p.uniacid=:uniacid and f.mem_id=:mem_id ORDER BY f.fund_id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
						$params = array(":fund_true" => true, ":uniacid" => $uniacid, ":mem_id" => $mem_id);
						$list = pdo_fetchall($sql, $params);
						$total = pdo_fetchcolumn('SELECT count(*) FROM ' . tablename('tim_welfare_fund') . ' f 
			left join ' . tablename('tim_welfare_project') . ' p on f.pro_id=p.pro_id
			WHERE f.fund_true=:fund_true and p.uniacid=:uniacid and f.mem_id=:mem_id', array(":fund_true" => true, ":uniacid" => $uniacid, ":mem_id" => $mem_id));
						$pager = pagination($total, $pindex, $psize);
						include $this->template('phb');
					}
				}
			}
		}
	}
	public function doWebmessage()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ($op == 'ok') {
			$comment_id = intval($_GPC['comment_id']);
			$data['state'] = 1;
			pdo_update('tim_welfare_comment', $data, array("comment_id" => $comment_id));
			header('location:' . $this->createWebUrl('message', array("op" => "display")));
		} else {
			if ($op == 'del') {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_comment') . '  where comment_id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$comment_id = intval($_GPC['comment_id']);
				$row = pdo_fetch('SELECT comment_id FROM ' . tablename('tim_welfare_comment') . ' WHERE comment_id = :comment_id', array(":comment_id" => $comment_id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('message', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_comment', array("comment_id" => $comment_id));
				message('删除成功！', referer(), 'success');
			} else {
				if ($op == 'display') {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$where = '';
					$mem_name = $_GPC['mem_name'];
					if (!empty($mem_name)) {
						$where .= ' and m.mem_name like \'%' . $mem_name . '%\'';
					}
					$pro_id = $_GPC['pro_id'];
					if (!empty($pro_id)) {
						$where .= ' and c.pro_id =' . $pro_id;
					}
					$state = $_GPC['states'];
					if (!empty($state)) {
						$where .= ' and c.state =' . $state;
					} else {
						$where .= ' and c.state = 0';
					}
					$pro = pdo_fetchall('SELECT pro_name,pro_id FROM ' . tablename('tim_welfare_project') . ' 
			WHERE uniacid=:uniacid ', array(":uniacid" => $uniacid));
					$sql = 'SELECT c.*,m.mem_name,p.pro_name FROM ' . tablename('tim_welfare_comment') . ' c
			left join ' . tablename('tim_welfare_member') . ' m on c.mem_id=m.mem_id
			left join ' . tablename('tim_welfare_project') . ' p on c.pro_id=p.pro_id
			WHERE p.uniacid=:uniacid ' . $where . ' ORDER BY c.time DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_comment') . ' c 
			left join ' . tablename('tim_welfare_member') . ' m on c.mem_id=m.mem_id
			WHERE m.uniacid=:uniacid and m.mem_name <> \'\' ' . $where, array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('message');
				} else {
					if ($op == 'message') {
						$comment_id = $_GPC['comment_id'];
						$pro_id = $_GPC['pro_id'];
						if ($_GPC['flag'] == 'add') {
							$data['parent_id'] = $comment_id;
							$data['pro_id'] = $pro_id;
							$data['mem_id'] = 0;
							$data['comment_cont'] = $_GPC['comment_cont'];
							$data['state'] = 1;
							$data['time'] = time();
							$res = pdo_insert('tim_welfare_comment', $data);
							if ($res) {
								message('添加留言成功！', $this->createWebUrl('message', array("op" => "display", "states" => "1")), 'success');
							} else {
								message('添加留言失败！', '', 'error');
							}
						} else {
							include $this->template('message');
						}
					}
				}
			}
		}
	}
	public function doWebjkmx()
	{
		global $_W, $_GPC;
		if (checksubmit('submit')) {
			$fund_value = $_GPC['fund_value'];
			if (empty($fund_value)) {
				message('亲,捐款金额不能为空！');
			}
			$data = array("pro_id" => $_GPC['pro_id'], "mem_id" => $_GPC['mem_id'], "order_num" => "", "fund_value" => $fund_value, "fund_true" => 1, "fund_time" => time(), "type" => "MONEY");
			pdo_insert('tim_welfare_fund', $data);
			echo '<script>parent.location.reload();</script>';
		} else {
			$uniacid = $_W['uniacid'];
			$mem_id = $_GPC['mem_id'];
			$project = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_project') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
			include $this->template('jkmx');
		}
	}
	public function doWebCustomModel()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		if ($_GPC['flag'] == '1') {
			pdo_delete('tim_welfare_custom', array("id" => $_GPC['id']));
		}
		if (!empty($_GPC['delete'])) {
			$i = 0;
			while ($i < count($_GPC['delete'])) {
				pdo_delete('tim_welfare_custom', array("id" => $_GPC['delete'][$i]));
				$i++;
			}
		}
		$sql = 'SELECT * FROM ' . tablename('tim_welfare_custom') . ' WHERE uniacid=:uniacid order by add_time desc';
		$params = array(":uniacid" => $uniacid);
		$list = pdo_fetchall($sql, $params);
		$op = 'list';
		include $this->template('custom');
	}
	public function doWebDoCustom()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		if (checksubmit('add')) {
			$data['uniacid'] = $uniacid;
			$data['name'] = $_GPC['name'];
			$data['photo'] = $_GPC['photo'];
			$data['ewm'] = $_GPC['ewm'];
			$data['logo'] = $_GPC['logo'];
			$data['content1'] = $_GPC['content1'];
			$data['content2'] = $_GPC['content2'];
			$data['content3'] = $_GPC['content3'];
			$data['add_time'] = time();
			$sql = 'SELECT * FROM ' . tablename('tim_welfare_custom') . ' WHERE `uniacid` = :uniacid';
			$params = array(":uniacid" => $uniacid);
			$count = pdo_fetchcolumn($sql, $params);
			if ($count >= 2) {
				message('最多添加两种证书！', '', 'error');
			} else {
				if (pdo_insert('tim_welfare_custom', $data)) {
					message('添加模版自定义成功！', $this->createWebUrl('customModel', array()), 'success');
				} else {
					message('添加模版自定义失败！', '', 'error');
				}
			}
		}
		if (checksubmit('update')) {
			$data['uniacid'] = $uniacid;
			$data['name'] = $_GPC['name'];
			$data['photo'] = $_GPC['photo'];
			$data['ewm'] = $_GPC['ewm'];
			$data['logo'] = $_GPC['logo'];
			$data['content1'] = $_GPC['content1'];
			$data['content2'] = $_GPC['content2'];
			$data['content3'] = $_GPC['content3'];
			$data['add_time'] = time();
			if (pdo_update('tim_welfare_custom', $data, array("id" => $_GPC['id']))) {
				message('编辑模版自定义成功', $this->createWebUrl('customModel', array()), 'success');
			} else {
				message('编辑模版自定义失败', '', 'error');
			}
		}
		$op = $_GPC['op'];
		if ($op == 'update') {
			$sql = 'SELECT * FROM ' . tablename('tim_welfare_custom') . ' WHERE `id` = :id';
			$params = array(":id" => $_GPC['id']);
			$cus = pdo_fetch($sql, $params);
		}
		include $this->template('custom');
	}
	public function doWebCustomImg()
	{
		global $_GPC;
		$content1 = $_GPC['content1'] == '' ? '全民公益平台' : $_GPC['content1'];
		$content2 = $_GPC['content2'] == '' ? '奉献微爱心，关爱青少年，每一笔捐赠都承载着希望与寄托! 我们相信，涓涓细流一定能汇聚成爱的海洋。感谢您的支持和信任，公益路上请继续与我们携手同行！' : $_GPC['content2'];
		$content3 = $_GPC['content3'] == '' ? '全民公益组织' : $_GPC['content3'];
		if (empty($_GPC['photo'])) {
			$_GPC['photo'] = 'addons/tim_welfare/template/mobile/img/bj1.jpg';
		}
		$ewm = $_GPC['ewm'];
		$logo = $_GPC['logo'];
		echo $this->createImg($_GPC['photo'], $ewm, $logo, $content1, $content2, $content3);
	}
	public function createImg($bj, $ewm, $avatar, $s1, $s2, $s3)
	{
		$s1 = str_replace('&quot;', '"', $s1);
		$s2 = str_replace('&quot;', '"', $s2);
		$s3 = str_replace('&quot;', '"', $s3);
		$bj = tomedia($bj);
		list($width, $height, $type) = getimagesize($bj);
		if ($type == 1) {
			$src_im = imagecreatefromgif($bj);
		} else {
			if ($type == 2) {
				$src_im = imagecreatefromjpeg($bj);
			} else {
				if ($type == 3) {
					$src_im = imagecreatefrompng($bj);
				} else {
					exit;
				}
			}
		}
		$ewm = tomedia($ewm);
		if ($ewm != '') {
			$ewmwidth = 240;
			$ewmheight = 240;
			$ewms = 1050;
			$ewmz = 460;
			$src_im1 = imagecreatefromstring(file_get_contents($ewm));
			$dst_im = imagecreatetruecolor($ewmwidth, $ewmheight);
			$ext = strrchr($ewm, '.');
			if ($ext == '.png') {
				$color = imagecolorallocate($dst_im, 255, 255, 255);
				imagecolortransparent($dst_im, $color);
				imagefill($dst_im, 0, 0, $color);
			}
			@imagecopyresized($dst_im, $src_im1, 0, 0, 0, 0, $ewmwidth, $ewmheight, imagesx($src_im1), imagesy($src_im1));
			imagecopymerge($src_im, $dst_im, $ewmz, $ewms, 0, 0, $ewmwidth, $ewmheight, 100);
		}
		$avatar = tomedia($avatar);
		if ($avatar != '') {
			$ewmwidth = 100;
			$ewmheight = 100;
			$ewms = 700;
			$ewmz = 580;
			$src_im1 = imagecreatefromstring(file_get_contents($avatar));
			$dst_im = imagecreatetruecolor($ewmwidth, $ewmheight);
			$ext = strrchr($avatar, '.');
			if ($ext == '.png') {
				$color = imagecolorallocate($dst_im, 255, 255, 255);
				imagecolortransparent($dst_im, $color);
				imagefill($dst_im, 0, 0, $color);
			}
			@imagecopyresized($dst_im, $src_im1, 0, 0, 0, 0, $ewmwidth, $ewmheight, imagesx($src_im1), imagesy($src_im1));
			imagecopymerge($src_im, $dst_im, $ewmz, $ewms, 0, 0, $ewmwidth, $ewmheight, 100);
		}
		$font_color = ImageColorAllocate($src_im, 0, 0, 0);
		$font_color1 = ImageColorAllocate($src_im, 92, 184, 92);
		$font_file1 = MODULE_ROOT . '/simkai1.ttf';
		$font_file2 = MODULE_ROOT . '/simkai2.ttf';
		if (mb_strlen($s2) > 24) {
			$text = mb_substr($s2, 0, 24, 'utf-8');
			imagettftext($src_im, 18, 0, 100, 600, $font_color, $font_file2, $text);
			$text1 = mb_substr($s2, 24, 26, 'utf-8');
			imagettftext($src_im, 18, 0, 65, 645, $font_color, $font_file2, $text1);
			if (mb_strlen($s2) > 50) {
				$text2 = mb_substr($s2, 50, 26, 'utf-8');
				imagettftext($src_im, 18, 0, 65, 690, $font_color, $font_file2, $text2);
				if (mb_strlen($s2) > 76) {
					$text3 = mb_substr($s2, 76, 26, 'utf-8');
					imagettftext($src_im, 18, 0, 65, 735, $font_color, $font_file2, $text3);
				}
			}
		} else {
			imagettftext($src_im, 18, 0, 100, 600, $font_color, $font_file2, $s2);
		}
		$k = 36;
		$i = ($k - strlen($s3)) / 3;
		$j = 435 + 24 * $i;
		imagettftext($src_im, 18, 0, $j, 790, $font_color, $font_file2, $s3);
		$text4 = '____年__月__日';
		imagettftext($src_im, 18, 0, 525, 830, $font_color, $font_file2, $text4);
		$text5 = '尊敬的______:';
		imagettftext($src_im, 20, 0, 65, 450, $font_color, $font_file1, $text5);
		$s1 = '截至____年__月__日，你在' . $s1 . '上捐赠___次，捐款___元。';
		$text6 = mb_substr($s1, 0, 28, 'utf-8');
		imagettftext($src_im, 18, 0, 100, 500, $font_color, $font_file1, $text6);
		$text7 = mb_substr($s1, 28, 65, 'utf-8');
		imagettftext($src_im, 18, 0, 65, 550, $font_color, $font_file1, $text7);
		$text8 = '捐款证书';
		imagettftext($src_im, 45, 0, 260, 360, $font_color1, $font_file1, $text8);
		header('Content-type: image/png');
		imagejpeg($src_im);
		imagedestroy($src_im);
	}
	public function doMobileDiploma()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		mc_oauth_userinfo();
		$openid = $_W['fans']['tag']['openid'];
		$user = pdo_fetch('SELECT mem_id FROM ' . tablename('tim_welfare_member') . ' WHERE openid=:openid', array(":openid" => $openid));
		$sql = 'SELECT sum(f.fund_value) as sum,count(f.pro_id) as count FROM ' . tablename('tim_welfare_member') . ' m
			left join ' . tablename('tim_welfare_fund') . ' f on f.mem_id=m.mem_id and f.fund_true=:fund_true
			WHERE m.uniacid=:uniacid and m.mem_id = :mem_id';
		$params = array(":fund_true" => true, ":uniacid" => $uniacid, ":mem_id" => $user['mem_id']);
		$list = pdo_fetch($sql, $params);
		include $this->template('diploma');
	}
	public function doMobileDodiploma()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$name = $_GPC['name'];
		include $this->template('dodiploma');
	}
	public function doMobilecustom1()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$openid = $_W['openid'];
		$user = pdo_fetch('SELECT mem_id FROM ' . tablename('tim_welfare_member') . ' WHERE openid=:openid', array(":openid" => $openid));
		$fund = pdo_fetch('SELECT count(*) as count,sum(fund_value) as sum FROM ' . tablename('tim_welfare_fund') . ' WHERE mem_id=:mem_id AND fund_true=:fund_true', array(":mem_id" => $user['mem_id'], ":fund_true" => true));
		$time = date('Y.m.d');
		$arr = explode('.', $time);
		$custom = pdo_fetchall('SELECT * FROM ' . tablename('tim_welfare_custom'));
		$name = $_GPC['name'];
		$flag = $_GPC['flag'];
		if ($flag == 1) {
			$custom = $custom[0];
		} else {
			if ($flag == 2) {
				$custom = $custom[1];
			}
		}
		echo $this->createImg_1($custom, $name, $arr, $fund);
	}
	public function createImg_1($custom, $name, $arr, $fund)
	{
		$bj = tomedia($custom['photo']);
		list($width, $height, $type) = getimagesize($bj);
		if ($type == 1) {
			$src_im = imagecreatefromgif($bj);
		} else {
			if ($type == 2) {
				$src_im = imagecreatefromjpeg($bj);
			} else {
				if ($type == 3) {
					$src_im = imagecreatefrompng($bj);
				} else {
					exit;
				}
			}
		}
		$ewm = tomedia($custom['ewm']);
		if ($ewm != '') {
			$ewmwidth = 240;
			$ewmheight = 240;
			$ewms = 1050;
			$ewmz = 460;
			$src_im1 = imagecreatefromstring(file_get_contents($ewm));
			$dst_im = imagecreatetruecolor($ewmwidth, $ewmheight);
			$ext = strrchr($ewm, '.');
			if ($ext == '.png') {
				$color = imagecolorallocate($dst_im, 255, 255, 255);
				imagecolortransparent($dst_im, $color);
				imagefill($dst_im, 0, 0, $color);
			}
			@imagecopyresized($dst_im, $src_im1, 0, 0, 0, 0, $ewmwidth, $ewmheight, imagesx($src_im1), imagesy($src_im1));
			imagecopymerge($src_im, $dst_im, $ewmz, $ewms, 0, 0, $ewmwidth, $ewmheight, 100);
		}
		$avatar = tomedia($custom['logo']);
		if ($avatar != '') {
			$ewmwidth = 100;
			$ewmheight = 100;
			$ewms = 700;
			$ewmz = 580;
			$src_im1 = imagecreatefromstring(file_get_contents($avatar));
			$dst_im = imagecreatetruecolor($ewmwidth, $ewmheight);
			$ext = strrchr($avatar, '.');
			if ($ext == '.png') {
				$color = imagecolorallocate($dst_im, 255, 255, 255);
				imagecolortransparent($dst_im, $color);
				imagefill($dst_im, 0, 0, $color);
			}
			@imagecopyresized($dst_im, $src_im1, 0, 0, 0, 0, $ewmwidth, $ewmheight, imagesx($src_im1), imagesy($src_im1));
			imagecopymerge($src_im, $dst_im, $ewmz, $ewms, 0, 0, $ewmwidth, $ewmheight, 100);
		}
		$font_color = ImageColorAllocate($src_im, 0, 0, 0);
		$font_color1 = ImageColorAllocate($src_im, 92, 184, 92);
		$font_file1 = MODULE_ROOT . '/simkai1.ttf';
		$font_file2 = MODULE_ROOT . '/simkai2.ttf';
		if (mb_strlen($custom['content2']) > 24) {
			$text = mb_substr($custom['content2'], 0, 24, 'utf-8');
			imagettftext($src_im, 18, 0, 100, 600, $font_color, $font_file2, $text);
			$text1 = mb_substr($custom['content2'], 24, 26, 'utf-8');
			imagettftext($src_im, 18, 0, 65, 645, $font_color, $font_file2, $text1);
			if (mb_strlen($custom['content2']) > 50) {
				$text2 = mb_substr($custom['content2'], 50, 26, 'utf-8');
				imagettftext($src_im, 18, 0, 65, 690, $font_color, $font_file2, $text2);
				if (mb_strlen($custom['content2']) > 76) {
					$text3 = mb_substr($custom['content2'], 76, 26, 'utf-8');
					imagettftext($src_im, 18, 0, 65, 735, $font_color, $font_file2, $text3);
				}
			}
		} else {
			imagettftext($src_im, 18, 0, 100, 600, $font_color, $font_file2, $custom['content2']);
		}
		$k = 36;
		$i = ($k - strlen($custom['content3'])) / 3;
		$j = 435 + 24 * $i;
		imagettftext($src_im, 18, 0, $j, 790, $font_color, $font_file2, $custom['content3']);
		$text4 = '____年__月__日';
		imagettftext($src_im, 18, 0, 525, 830, $font_color, $font_file2, $text4);
		imagettftext($src_im, 18, 0, 525, 830, $font_color, $font_file2, $arr[0]);
		imagettftext($src_im, 18, 0, 615, 830, $font_color, $font_file2, $arr[1]);
		imagettftext($src_im, 18, 0, 670, 830, $font_color, $font_file2, $arr[2]);
		$text5 = '尊敬的______:';
		imagettftext($src_im, 20, 0, 65, 450, $font_color, $font_file1, $text5);
		imagettftext($src_im, 20, 0, 150, 450, $font_color, $font_file1, $name);
		$s1 = '截至 ' . $arr[0] . ' 年 ' . $arr[1] . ' 月 ' . $arr[2] . '日，你在' . $custom['content1'] . '上捐赠 ' . $fund['count'] . ' 次，捐款 ' . $fund['sum'] . ' 元。';
		$text6 = mb_substr($s1, 0, 32, 'utf-8');
		imagettftext($src_im, 18, 0, 100, 500, $font_color, $font_file1, $text6);
		$text7 = mb_substr($s1, 32, 65, 'utf-8');
		imagettftext($src_im, 18, 0, 65, 550, $font_color, $font_file1, $text7);
		$text8 = '捐款证书';
		imagettftext($src_im, 45, 0, 260, 360, $font_color1, $font_file1, $text8);
		header('Content-type: image/png');
		imagejpeg($src_im);
		imagedestroy($src_im);
	}
	public function doMobileCount()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$count = pdo_fetch('SELECT sum(f.fund_value) as sum,count(distinct p.pro_id) as pro,count(distinct f.mem_id) as count FROM ' . tablename('tim_welfare_project') . ' p
			left join ' . tablename('tim_welfare_fund') . ' f on f.pro_id=p.pro_id and f.fund_true=:fund_true
			WHERE uniacid=:uniacid', array(":fund_true" => true, ":uniacid" => $uniacid));
		$list = pdo_fetchall('SELECT sum(f.fund_value) as sum,c.class_name FROM ' . tablename('tim_welfare_class') . ' c
			left join ' . tablename('tim_welfare_project') . ' p on c.class_id=p.class_id 
			left join ' . tablename('tim_welfare_fund') . ' f on f.pro_id=p.pro_id and f.fund_true=:fund_true
			WHERE c.uniacid=:uniacid GROUP BY p.class_id', array(":fund_true" => true, ":uniacid" => $uniacid));
		$data = '';
		$str = '';
		$arr = array();
		foreach ($list as $val) {
			$arr[] = $val['class_name'];
			$str .= '{value:' . round($val['sum'], 2) . ',name:\'' . $val['class_name'] . '\'},';
		}
		$arr = array_reverse($arr);
		foreach ($arr as $k => $val) {
			$data .= $val . '\',\'';
		}
		$str = rtrim($str, ',');
		$data = '[\'' . rtrim($data, '\',\'') . '\']';
		include $this->template('count');
	}
	public function doWebArticle()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		load()->func('tpl');
		if ('post' == $op) {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array("uniacid" => $uniacid, "title" => $_GPC['title'], "images" => $_GPC['images'], "short" => $_GPC['short'], "content" => $_GPC['content'], "is_stick" => $_GPC['is_stick'], "add_time" => time());
				if (empty($id)) {
					pdo_insert('tim_welfare_article', $data);
					message('数据添加成功！', $this->createWebUrl('article', array("op" => "display")), 'success');
				} else {
					pdo_update('tim_welfare_article', $data, array("id" => $id));
					message('数据更新成功！', $this->createWebUrl('article', array("op" => "display")), 'success');
				}
			} else {
				$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_article') . ' WHERE id = :id', array(":id" => $id));
				include $this->template('article');
			}
		} else {
			if ('del' == $op) {
				if (isset($_GPC['delete'])) {
					$ids = implode(',', $_GPC['delete']);
					$sqls = 'delete from  ' . tablename('tim_welfare_article') . '  where id in(' . $ids . ')';
					pdo_query($sqls);
					message('删除成功！', referer(), 'success');
				}
				$id = intval($_GPC['id']);
				$row = pdo_fetch('SELECT id FROM ' . tablename('tim_welfare_article') . ' WHERE id = :id', array(":id" => $id));
				if (empty($row)) {
					message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('article', array("op" => "display")), 'error');
				}
				pdo_delete('tim_welfare_article', array("id" => $id));
				message('删除成功！', referer(), 'success');
			} else {
				if ('display' == $op) {
					$pindex = max(1, intval($_GPC['page']));
					$psize = 10;
					$sql = 'SELECT * FROM ' . tablename('tim_welfare_article') . ' WHERE uniacid=:uniacid ORDER BY is_stick DESC,id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
					$params = array(":uniacid" => $uniacid);
					$list = pdo_fetchall($sql, $params);
					$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tim_welfare_article') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
					$pager = pagination($total, $pindex, $psize);
					include $this->template('article');
				}
			}
		}
	}
	public function doMobileLooks()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$pindex = max(1, intval($_GPC['page']));
		$psize = 10;
		$sql = 'SELECT * FROM ' . tablename('tim_welfare_article') . ' WHERE uniacid=:uniacid ORDER BY is_stick DESC,id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
		$params = array(":uniacid" => $uniacid);
		$list = pdo_fetchall($sql, $params);
		$str = '';
		if ($_GPC['flag'] == 1) {
			foreach ($list as $val) {
				$str .= '<a href="' . $this->createMobileUrl('dolooks', array("id" => $val['id'])) . '"><div class="look_d bor_btm"><p class="look_d_p1">' . $val['title'] . '</p><div class="look_d_d1"><div class="look_d_d1d1"><img src="' . $_W['attachurl'] . $val['images'] . '"></div><div class="look_d_d1d2"><p class="look_d_d1d2_p1">' . $val['short'] . '</p><p class="look_d_d1d2_p2">' . date('Y-m-d H:i:s', $val['add_time']) . '</p></div><div class="clearfix"></div></div></div></a>';
			}
			return $str;
			exit;
		}
		include $this->template('looks');
	}
	public function doMobileDolooks()
	{
		global $_W, $_GPC;
		$uniacid = $_W['uniacid'];
		$set = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_set') . ' WHERE uniacid=:uniacid', array(":uniacid" => $uniacid));
		$item = pdo_fetch('SELECT * FROM ' . tablename('tim_welfare_article') . ' WHERE uniacid=:uniacid and id=:id', array(":uniacid" => $uniacid, ":id" => $_GPC['id']));
		include $this->template('dolooks');
	}
}